package com.shopoo.oauth.infrastructure.repository;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shopoo.oauth.domain.entity.User;
import com.shopoo.oauth.domain.repository.UserRoleRepository;
import com.shopoo.oauth.infrastructure.assembler.InfrastructureAssembler;
import com.shopoo.oauth.infrastructure.database.dataobject.OauthUserRoleR;
import com.shopoo.oauth.infrastructure.database.mapper.UserRoleMapper;

import org.springframework.stereotype.Repository;

/**
 * @Description 用户角色数据仓库实现
 * @Date 2020/12/3 11:10 上午
 * @Author <a href="mailto:android_li@sina.cn">Joe</a>
 **/
@Repository
public class UserRoleRepositoryImpl extends ServiceImpl<UserRoleMapper, OauthUserRoleR> implements UserRoleRepository {

    @Override
    public void deleteByUserId(String userId) {
        LambdaQueryWrapper<OauthUserRoleR> deleteWrapper = new LambdaQueryWrapper<>();
        deleteWrapper.eq(OauthUserRoleR::getUserId, userId);
        this.remove(deleteWrapper);
    }

    @Override
    public List<User> getByUserId(String userId) {
        LambdaQueryWrapper<OauthUserRoleR> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OauthUserRoleR::getUserId, userId);
        List<OauthUserRoleR> list = super.list(queryWrapper);
        return InfrastructureAssembler.transferUserRoleList(list);
    }

    @Override
    public List<User> getByRoleId(Long roleId) {
        LambdaQueryWrapper<OauthUserRoleR> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OauthUserRoleR::getRoleId, roleId);
        List<OauthUserRoleR> list = super.list(queryWrapper);
        return InfrastructureAssembler.transferUserRoleList(list);
    }
}
